#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
inline int Inv(int x){
	int ans=1;
	for(int y=mod-2;y;y>>=1,x=1ll*x*x%mod)
		if(y&1) ans=1ll*ans*x%mod;
	return ans;
}
int ans,fac[20],ifac[20],T,n[20],len,c[10],mx,nu,b[10];
inline void sol(int m){
	int mul=fac[m];
	for(int i=0;i<=9;++i) mul=1ll*mul*ifac[c[i]]%mod;
	ans=(ans+1ll*mul*nu%mod)%mod;
	if(c[0]){
		mul=1ll*fac[m-1]*ifac[c[0]-1]%mod;
		for(int i=1;i<=9;++i) mul=1ll*mul*ifac[c[i]]%mod;
		ans=(1ll*ans+mod-1ll*mul*nu%mod)%mod;
	}
}
void dfs(int x,int res){
	if(x==10){
		if(res) return sol(len-res),void();
		int mul=1,flag=1;
		for(int i=0;i<=9;++i) mul=1ll*mul*ifac[b[i]=c[i]]%mod;
		for(int i=len;i;--i){
			for(int j=(i==len);j<n[i];++j)if(b[j]){
				ans=(ans+1ll*mul*fac[b[j]]%mod*ifac[b[j]-1]%mod*fac[i-1]%mod*nu%mod)%mod;
			}
			if(b[n[i]]==0){
				flag=0;
				break;
			}
			mul=1ll*fac[b[n[i]]]*mul%mod;
			mul=1ll*ifac[--b[n[i]]]*mul%mod;
		}
		ans=(ans+flag*nu)%mod;
		return;
	}
	if(x==nu){
		dfs(x+1,res);
		return;
	}
	for(int i=0;i<=mx-(x>nu)&&i<=res;++i)
		c[x]=i,dfs(x+1,res-i);
}
int main(){
	freopen("give.in","r",stdin);
	freopen("give.out","w",stdout);
	fac[0]=ifac[0]=1;
	for(int i=1;i<20;++i) fac[i]=1ll*fac[i-1]*i%mod,ifac[i]=Inv(fac[i]); 
	scanf("%d",&T);
	while(T--){
		long long N;
		scanf("%lld",&N);
		len=0;ans=0;
		while(N) n[++len]=N%10,N/=10;
		for(nu=1;nu<=9;++nu)
		for(mx=(len+9)/10;mx<=len;++mx)
			c[nu]=mx,dfs(0,len-mx);
		printf("%d\n",ans);
	}
	return 0;
}

